# ————————————————————  9.10.1异常概述  ————————————————————
# print(1 / 0)

# print(name)

# list_demo = [1, 2, 3, 4]
# print(list_demo[4])

# class Dog:
#     pass
# dog = Dog()
# print(dog.name)

# file = open("test.txt")


# ————————————————————  9.10.2捕获与处理异常  ————————————————————
# num_one = int(input("被除数："))
# num_two = int(input("除数："))
# try:
#     print("商：", num_one / num_two)
# except ZeroDivisionError:
#     print("出错了")

# num_one = int(input("被除数："))
# num_two = int(input("除数："))
# try:
#     print("商：", num_one / num_two)
# except ZeroDivisionError as error:
#     print("出错了，原因：", error)

# try:
#     num_one = int(input("被除数："))
#     num_two = int(input("除数："))
#     print("商：", num_one / num_two)
# except (ZeroDivisionError, ValueError) as error:
#     print("出错了，原因：", error)

# try:
#     num_one = int(input("被除数："))
#     num_two = int(input("除数："))
#     print("商：", num_one / num_two)
# except Exception as error:
#     print("出错了，原因：", error)

# try:
#     num_one = int(input("被除数："))
#     num_two = int(input("除数："))
#     result = num_one / num_two
# except Exception as error:
#     print("出错了，原因：", error)
# else:
#     print("商：", result)

# file = open('test.txt', 'r')
# try:
#     file.write("人生苦短，我用Python")
# except Exception as error:
#     print("写入文件失败", error)
# finally:
#     file.close()
#     print('文件已关闭')


# ————————————————————  9.10.3抛出异常  ————————————————————
# raise IndexError
# raise IndexError()
# raise IndexError('索引下标超出范围')      # 抛出异常及其具体信息
# raise

num_one = int(input("被除数："))
num_two = int(input("除数："))
assert num_two != 0, '除数不能为0'         # assert语句判定num_two不等于0
result = num_one / num_two
print(num_one, '/', num_two, '=', result)
